using Microsoft.Extensions.Logging;
using ConsoleApi.Models;
using ConsoleApi.Services.Interfaces;

namespace ConsoleApi.Services;

/// <summary>
/// 生产数据服务实现
/// </summary>
public class ProductionDataService : IProductionDataService
{
    private readonly ILogger<ProductionDataService> _logger;

    public ProductionDataService(ILogger<ProductionDataService> logger)
    {
        _logger = logger;
    }

    public async Task<List<ProductionActivity>> GetProductionActivitiesAsync(string activityType)
    {
        _logger.LogInformation("获取生产活动列表: {ActivityType}", activityType);
        
        await Task.Delay(50);
        
        return activityType switch
        {
            "户外作业" => new List<ProductionActivity>
            {
                new() { Id = "1", Name = "建筑施工作业", Type = "户外", IsOutdoor = true },
                new() { Id = "2", Name = "设备安装调试", Type = "户外", IsOutdoor = true },
                new() { Id = "3", Name = "现场巡检", Type = "户外", IsOutdoor = true }
            },
            "物流运输" => new List<ProductionActivity>
            {
                new() { Id = "4", Name = "货物运输", Type = "物流", IsOutdoor = false },
                new() { Id = "5", Name = "仓储作业", Type = "物流", IsOutdoor = false }
            },
            "设备维护" => new List<ProductionActivity>
            {
                new() { Id = "6", Name = "设备检修", Type = "维护", IsOutdoor = false },
                new() { Id = "7", Name = "预防性维护", Type = "维护", IsOutdoor = false }
            },
            _ => new List<ProductionActivity>
            {
                new() { Id = "8", Name = "通用生产活动", Type = "通用", IsOutdoor = false }
            }
        };
    }

    public async Task<ProductionStatistics> GetProductionStatisticsAsync(string city, DateTime date)
    {
        _logger.LogInformation("获取生产统计数据: {City}, {Date}", city, date);
        
        await Task.Delay(50);
        
        var random = new Random();
        
        return new ProductionStatistics
        {
            City = city,
            Date = date,
            TotalActivities = random.Next(50, 200),
            CompletedActivities = random.Next(30, 150),
            DelayedActivities = random.Next(5, 30),
            Efficiency = random.Next(70, 95) / 100.0,
            WeatherImpacts = new List<string> { "高温影响", "降雨延迟" }
        };
    }

    public async Task<bool> UpdateActivityStatusAsync(string activityId, string status)
    {
        _logger.LogInformation("更新生产活动状态: {ActivityId}, {Status}", activityId, status);
        
        await Task.Delay(50);
        
        // 模拟更新操作
        return true;
    }
} 